//============================================================================
// Name        : abstract_factory.cpp
// Author      : Tony
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

class ProductA
{
public:
	ProductA()
	{
		cout<<"construct productA"<<endl;
	}

};

class ProductA1 : public ProductA
{
public:
	ProductA1()
	{
		cout<<"construct ProductA1"<<endl;
	}
};

class ProductA2 : public ProductA
{
public:
	ProductA2()
	{
		cout<<"construct ProductA2"<<endl;
	}
};

class ProductB
{
public:
	ProductB()
	{
		cout<<"construct ProductB"<<endl;
	}
};

class ProductB1 : public ProductB
{
public:
	ProductB1()
	{
		cout<<"construct ProductB1"<<endl;
	}
};

class ProductB2 : public ProductB
{
public:
	ProductB2()
	{
		cout<<"construct ProductB2"<<endl;
	}
};


class abstractFactory
{
public:
	abstractFactory(){}
	virtual ~abstractFactory(){}
	virtual ProductA* createProductA() = 0;
	virtual ProductB* createProductB() = 0;
};

class Factory1 : public abstractFactory
{
public:
	virtual ProductA* createProductA()
	{
		return new ProductA1();
	}
	virtual ProductB* createProductB()
	{
		return new ProductB1();
	}
};

class Factory2 : public abstractFactory
{
public:
	virtual ProductA* createProductA()
	{
		return new ProductA2();
	}
	virtual ProductB* createProductB()
	{
		return new ProductB2();
	}
};

int main() {
	abstractFactory* factory = new Factory1();
	ProductA* productA = factory->createProductA();
	ProductB* productB = factory->createProductB();

	delete factory;
	delete productA;
	delete productB;

	cout<<"===================="<<endl;

	factory = new Factory2();
	productA = factory->createProductA();
	productB = factory->createProductB();

	delete factory;
	delete productA;
	delete productB;

	return 0;
}
